package com.tronsis.distribution.activity.me;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.tronsis.distribution.R;
import com.tronsis.library.activity.ToolBarBaseActivity;
import com.tronsis.library.adapter.recyclerview.CommonAdapter;
import com.tronsis.library.adapter.recyclerview.base.ViewHolder;
import com.tronsis.library.util.DisplayUtil;
import com.tronsis.library.widget.MyDecoration;
import com.tronsis.library.widget.RecycleViewDivider;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class StockProcessingDetailActivity extends ToolBarBaseActivity {
    @BindView(R.id.rv_goods)
    RecyclerView mRvGoods;
    @BindView(R.id.tv_more)
    TextView mTvMore;

    private CommonAdapter<String> mAdapter;
    private List<String> mGoodsList = new ArrayList<>();
    private List<String> mGoodsAllList = new ArrayList<>();
    private List<String> mGoodsPartList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_stock_processing_detail);
        setTitle(true, getString(R.string.order_detail));
        initRv();
        initData();
    }

    private void initData() {
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");
        mGoodsAllList.add("1");

        mGoodsList.clear();
        if (mGoodsAllList.size() > 6) {
            mTvMore.setVisibility(View.VISIBLE);
            for (int i = 0; i < 6; i++) {
                mGoodsPartList.add(mGoodsAllList.get(i));
            }
            mGoodsList.addAll(mGoodsPartList);
        } else {
            mGoodsList.addAll(mGoodsAllList);
        }
        mAdapter.notifyDataSetChanged();
    }

    private void initRv() {
        mAdapter = new CommonAdapter<String>(mContext, mGoodsList, R.layout.item_order_goods) {
            @Override
            protected void convert(ViewHolder holder, String s, int position) {

            }
        };


        int height = DisplayUtil.getInstance(mContext).dp2px(1);
        int color = Color.parseColor("#F4F4F4");
        RecycleViewDivider decoration = new RecycleViewDivider(mContext, MyDecoration.VERTICAL_LIST, height, color);
        mRvGoods.addItemDecoration(decoration);
        mRvGoods.setLayoutManager(new LinearLayoutManager(mContext));
        mRvGoods.setHasFixedSize(true);
        mRvGoods.setNestedScrollingEnabled(false);
        mRvGoods.setAdapter(mAdapter);
    }

    @OnClick(R.id.tv_more)
    void onMoreClick() {
        if (mGoodsList.size() > 6) {
            mGoodsList.clear();
            mGoodsList.addAll(mGoodsPartList);
            mTvMore.setText(getString(R.string.format_view_all_goods, mGoodsAllList.size()));
        } else {
            mGoodsList.clear();
            mGoodsList.addAll(mGoodsAllList);
            mTvMore.setText("收起");
        }

        mAdapter.notifyDataSetChanged();
    }
}
